import 'package:compass/const/eight_trigrams.dart';
import 'package:compass/const/sixty_four_hexagrams_of_fu_xi.dart';
import 'package:compass/const/twenty_four_mountain.dart';
import 'package:flutter/cupertino.dart';

import '../const/direction.dart';
import '../const/type.dart';
import '../page/home_page.dart';
import '../style/theme.dart';
import '../utils/direction.dart';
import '../utils/math_utils.dart';

class CompassInfo extends StatefulWidget {
  double azimuth = 0;
  PositionInfo? positionInfo;

  CompassInfo({super.key, this.azimuth = 0, this.positionInfo});

  @override
  State<CompassInfo> createState() => _CompassInfoState();
}

class _CompassInfoState extends State<CompassInfo> {
  @override
  Widget build(BuildContext context) {
    double azimuth = widget.azimuth;
    PositionInfo? positionInfo = widget.positionInfo;
    Direction? direction = getDirection(directionRenderList, azimuth);
    Direction? eightTrigramsList =
        getDirection(eightTrigramsRenderList, azimuth);
    Direction? twentyFourMountain =
        getDirection(twentyFourMountainRenderList, azimuth);
    Direction? sixtyFourHexagramsOfFuXi =
        getDirection(sixtyFourHexagramsOfFuXiRenderList, azimuth);

    return Container(
      padding: const EdgeInsets.all(8),
      color: themeColorBgLight,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextItem.init(
                  '经度 ${degreesTransToShow(positionInfo?.longitude ?? 0)}'),
              TextItem.init(
                  '纬度 ${degreesTransToShow(positionInfo?.latitude ?? 0)}'),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextItem.init(
                '坐${direction?.seat?.txt} ${degreesTransfer(azimuth + 180).toStringAsFixed(2)}°',
              ),
              TextItem.init(
                '向${direction?.orientation?.txt} ${azimuth.toStringAsFixed(2)}°',
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const TextItem.init('后天八卦'),
              TextItem.init('${eightTrigramsList?.orientation?.txt}卦'),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const TextItem.init('二十四山'),
              TextItem.init(
                  '${twentyFourMountain?.seat?.txt}山${twentyFourMountain?.orientation?.txt}向 五行属${findFiveLineAttribute(twentyFourMountain?.orientation)} (${findYinYang(twentyFourMountain?.orientation)})'),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const TextItem.init('伏羲六十四卦'),
              TextItem.init('${sixtyFourHexagramsOfFuXi?.orientation?.txt}卦'),
            ],
          ),
        ],
      ),
    );
  }
}
